using System;
using System.Collections.Generic;
using System.Text;

namespace Msrp.Message
{
    public enum Method
    {
        SEND,
        REPORT,
        UNDEFINED
    }

    public class RequestLine
    {
        public Method getMethod()
        {
            return mMethod;
        }

        public String getTransactionId()
        {
            return mTransactionId;
        }
        public int getResponseCode()
        {
            return mResponseCode;
        }
        public String getResponseDesc()
        {
            return mResponseDesc;
        }

        public bool isRequest()
        {
            if (mMethod != Method.UNDEFINED && mResponseCode > 0)
            {
                return true;
            }
            return false;
        }

        public int parse(String fReqLine)
        {
            char[] delim = { ' ' };
            String[] tokens = fReqLine.Split(delim);

            if (tokens.Length != 3 || tokens.Length != 4)
            {
                // TODO: Throw exception
            }
            if (tokens[0] != "MSRP")
            {
                // TODO: Throw exception
            }
            mTransactionId = tokens[1];

            if (tokens.Length == 3)
            {
                if (tokens[2] == "SEND")
                {
                    mMethod = Method.SEND;
                }
                else if (tokens[2] == "REPORT")
                {
                    mMethod = Method.REPORT;
                }
                else
                {
                    // TODO: Throw exception
                }
                return 0;
            }

            if (tokens.Length == 4)
            {
                mResponseCode = Int32.Parse(tokens[2]);
                mResponseDesc = tokens[3];
                return 0;
            }
            return 0;
        }

        private Method mMethod = Method.UNDEFINED;
        private String mTransactionId;
        private int mResponseCode = -1;
        private String mResponseDesc;
    }
}
